<?php
/**
 * Flea Site
 *
 * @copyright  Copyright (c) 2008 Movoin Studio (http://movoin.com)
 * @license    Apache License 2.0
 * @version    $Id: Feedback.php 133 2009-05-23 07:49:13Z movoin $
 */

//{{include
FLEA::loadClass('Controller_Base');
//}}

class Controller_Feedback extends Controller_Base
{

    var $modelFeedback;

    function Controller_Feedback()
    {
        parent::Controller_Base();
        $this->modelFeedback =& FLEA::getSingleton( 'Model_Feedback' );
    }

    function actionIndex()
    {
        $this->_setBack();
        $data['focus'] = 'column';
        $data['column'] = $this->getColumnInf( $_GET[FLEA::getAppInf( 'columnAccessor' )] );
        $data['label'] = '订单';

        $table =& $this->modelFeedback->getTable();
        $where = array(
            array( 'col_key', $_GET[FLEA::getAppInf( 'columnAccessor' )] ),
            array( 'site_id', (int)$_GET['site'] )
            );
        FLEA::loadHelper( 'pager' );
        $page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
        $pagesize = 10;
        $pager =& new FLEA_Helper_Pager($table, $page, $pagesize, $where, 'created DESC');
        $data['pager'] = $pager->getPagerData();
        $data['rows'] = $pager->findAll('comment_id,options');

        FLEA::loadFile( 'Helper_Common' );
        $this->_executeView('feedback', $data);
    }

    function actionView()
    {
        $data['focus'] = 'column';
        $data['column'] = $this->getColumnInf( $_GET[FLEA::getAppInf( 'columnAccessor' )] );
        $data['label'] = '订单';

        $data['row'] = $this->modelFeedback->getFeedback($_GET['commentid']);
        $data['meta'] = $this->modelFeedback->getMeta();
        FLEA::loadFile( 'Helper_Common' );

        if($data['row']['displayorder']==0)
            $this->modelFeedback->setReaded((int)$_GET['commentid']);

        $this->_executeView('feedback-view', $data);
    }

    function actionRemove()
    {
        js_alert($this->modelFeedback->remove($_GET['commentid']), 0, $this->_getBack());
    }

}
